﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;

namespace MovingChame.Web.Helpers
{
    public enum ImageType
    {
        TourImage,
        LocationImage
    }

    public static class ImageHelper
    {
        public static Image ConvertPathToImage(string fileName, ImageType imageType)
        {
            string path;
            if (imageType == ImageType.TourImage)
                path = HttpContext.Current.Server.MapPath(string.Format("{0}{1}", "~/TourImages/", fileName));
            else
                path = HttpContext.Current.Server.MapPath(string.Format("{0}{1}", "~/LocationImages/", fileName));
            return Image.FromFile(path);
        }

        public static byte[] ConvertImageToByteArray(Image image)
        {
            MemoryStream memoryStream = new MemoryStream();
            image.Save(memoryStream, ImageFormat.Jpeg);
            return memoryStream.ToArray();
        }

        public static Image ConvertByteArrayToImage(byte[] byteArray)
        {
            MemoryStream memoryStream = new MemoryStream(byteArray);
            return Image.FromStream(memoryStream);
        }
    }
}